home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre3.z / postgre3 / src / lib / H / nodes / nodes.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  5.5 KB  |  213 lines

  1. /*
  2.  * nodes.h --
  3.  *    Definitions for tagged nodes.
  4.  *
  5.  * Identification:
  6.  *    $Header: /private/postgres/src/lib/H/nodes/RCS/nodes.h,v 1.15 1992/07/24 21:20:12 mao Exp $
  7.  *
  8.  * NOTES:
  9.  *    Why do things this way, you ask.
  10.  *
  11.  *    (1) Eventually this code should be transmogrified into C++ classes,
  12.  *        and this is more or less compatible with those things.
  13.  *    (2) Unions suck.
  14.  *
  15.  *    As long as all inheritance declarations are put at the beginning of
  16.  *    the structure in a consistent order this is perfectly legal (sharing
  17.  *    of initial structure members is K&R C).
  18.  */
  19.  
  20. #ifndef NodesIncluded
  21. #define    NodesIncluded
  22.  
  23. #include "tmp/c.h"
  24. #include "tags.h" 
  25.  
  26. /* ----------------------------------------------------------------
  27.  *            miscellanious node defines
  28.  * ----------------------------------------------------------------
  29.  */
  30.  
  31. /* ----------------
  32.  *    NO_NODE_CHECKING, if defined, turns off the built in
  33.  *    argument sanity checking done within the generated
  34.  *    set_ and get_ accessor functions.
  35.  *
  36.  *    If not defined, then sanity checking is done.  This makes
  37.  *    things a bit slower but makes debugging easier..
  38.  * ----------------
  39.  */
  40.  
  41. /*
  42.  * We define NO_NODE_CHECKING for now because we are trying to get speed
  43.  * out of this thing...
  44.  */
  45.  
  46. #define NO_NODE_CHECKING
  47.  
  48. /* ----------------
  49.  *    I don't know why this is here.  Most likely a hack..
  50.  *    -cim 6/3/90
  51.  * ----------------
  52.  */
  53. typedef float Cost;
  54.  
  55. /*
  56.  *    Set up a single-inheritance mechanism based on cpp.  Ick.
  57.  *
  58.  *    public() is a noise-word that exists solely for our inheritance-graph
  59.  *      generation script.
  60.  */
  61.  
  62. #define    public(_x_)
  63. /*
  64.  *  inheritsN is necessary because ANSI C cpp doesn't expand a macro that
  65.  *  occurs in a definition more than once. 
  66.  *
  67.  *  example: now the old inherits macros would turn
  68.  *   class (Var) public (Expr) {
  69.  *            inherits(Expr);
  70.  *            Index            varno; 
  71.  *
  72.  *  into:
  73.  *    typedef struct _Var *Var; struct _Var {
  74.  *            inherits(Node);
  75.  *            Index  varno; 
  76.  *    ...
  77.  *
  78.  *  instead of:
  79.  *    typedef struct _Var *Var; struct _Var {
  80.  *            NodeTag    type;
  81.  *            void    (*outFunc)();
  82.  *            char     (*equalFunc)();
  83.  *            char     (*copyFunc)()    ;
  84.  *            Index     varno; 
  85.  *    ...
  86.  *    
  87.  *   so now we have inheritsN instead of inherits.  If you define
  88.  *   a subclass which inhertsN(foo) then you have to use inheritsN+1(foo)
  89.  *   or everything breaks.
  90.  */
  91.  
  92. #define    inherits0(_x_)    CppConcat0(_x_,Defs)
  93. #define    inherits1(_x_)    CppConcat1(_x_,Defs)
  94. #define    inherits2(_x_)    CppConcat2(_x_,Defs)
  95. #define    inherits3(_x_)    CppConcat3(_x_,Defs)
  96. #define    inherits4(_x_)    CppConcat4(_x_,Defs)
  97. #define    classObj(_x_)    struct CppConcat(_,_x_)
  98. #define    classSize(_x_)    ((Size) sizeof(classObj(_x_)))
  99. #define    classTag(_x_)    ((NodeTag) CppConcat(T_,_x_))
  100. #define    class(_x_)    typedef classObj(_x_) *_x_; classObj(_x_)
  101.  
  102. /*
  103.  * TypeId
  104.  * XXX An "enum" would be slightly cleaner but
  105.  *    (1) "enum" isn't universal yet
  106.  *    (2) the Saber disbelief of typedefs makes them a pain
  107.  */
  108.  
  109. typedef    unsigned int        TypeId;
  110. typedef unsigned int        NodeTag;
  111.  
  112. #define    TypeIdIsValid(t)    ((t) < (TypeId)_InvalidTypeId)
  113.  
  114. /* ----------------------------------------------------------------
  115.  *            Node class definition
  116.  *
  117.  *    The Node class is the superclass for all other classes
  118.  *    in this inheritance system.
  119.  * ----------------------------------------------------------------
  120.  */
  121.  
  122. class (Node) {
  123. #define    NodeDefs \
  124.     NodeTag            type;    \
  125.     void            (*outFunc)();    \
  126.     bool            (*equalFunc)(); \
  127.     bool            (*copyFunc)()
  128.  /* private: */
  129.     NodeDefs;
  130.  /* public: */
  131. };
  132.  
  133. #define NullTag            ((NodeTag) NULL)
  134. #define    NodeType(_node_)    ((Node)_node_)->type
  135. #define    NodeIsValid(_node_)    PointerIsValid((Pointer)(_node_))
  136.  
  137. #define    IsA(_node_,_tag_)    NodeIsType((Node)(_node_), classTag(_tag_))
  138. #define    New_Node(_x_)        ((_x_)NewNode(classSize(_x_),classTag(_x_)))
  139. #define CreateNode(_x_)        ((_x_)NewNode(classSize(_x_),classTag(_x_)))
  140.  
  141. /*
  142.  * "Clause" macros for finding various nodes follow
  143.  */
  144.  
  145. #define fast_is_clause(_clause_) (ExactNodeType(CAR((LispValue) _clause_),Oper))
  146. #define fast_is_funcclause(_clause_) (ExactNodeType(CAR((LispValue) _clause_),Func))
  147. #define fast_not_clause(_clause_) (CInteger(CAR((LispValue) _clause_)) == NOT)
  148. #define fast_or_clause(_clause_) (CInteger(CAR((LispValue) _clause_)) == OR)
  149. #define fast_and_clause(_clause_) (CInteger(CAR((LispValue) _clause_)) == AND)
  150.  
  151. /*
  152.  * NodeTagIsValid --
  153.  *      True iff node tag is valid.
  154.  */
  155. #define NodeTagIsValid(tag) \
  156.     ((bool)((tag) < _InvalidTypeId))
  157.  
  158. /*
  159.  * NodeGetTag --
  160.  *    Returns tag of a node.
  161.  *
  162.  * Note:
  163.  *    Assumes node is valid.
  164.  */
  165. #define NodeGetTag(node) \
  166.     ((NodeTag) (AssertMacro(NodeIsValid(node)) ? NodeType(node) : NullTag))
  167.  
  168. /*
  169.  * NodeSetTag --
  170.  *    Sets tag of a node.
  171.  *
  172.  * Note:
  173.  *    Assumes node is valid pointer.
  174.  *    Assumes tag is valid.
  175.  */
  176. #define NodeSetTag(node, tag) \
  177.     Assert(PointerIsValid(node)); \
  178.     Assert(NodeTagIsValid(tag)); \
  179.     NodeType(node) = tag
  180.  
  181. /*
  182.  * NodeHasTag --
  183.  *    True iff node or one of its ancestors has the given tag.
  184.  *
  185.  * Note:
  186.  *    See also:  NodeIsTagged.
  187.  */
  188. #define NodeHasTag(node, tag) \
  189.     ((bool) (NodeGetTag(node) == (tag)))
  190.  
  191. #define ExactNodeType(_node_,_tag_) \
  192.     (NodeType(_node_) == classTag(_tag_))
  193.  
  194. /* ----------------------------------------------------------------
  195.  *              extern declarations follow
  196.  * ----------------------------------------------------------------
  197.  */
  198.  
  199. /*
  200.  * NewNode --
  201.  *    Returns a new node of the given size and tag.
  202.  */
  203. extern
  204. Node
  205. NewNode ARGS((Size size, NodeTag tag ));
  206.  
  207. void SetNodeType ARGS((Node thisNode , TypeId tag ));
  208. Size NodeTagGetSize ARGS((TypeId tag ));
  209.  
  210. extern TypeId _InvalidTypeId;
  211.  
  212. #endif /* NodesIncluded */
  213.